#pragma once
#include <stdint.h>
#ifdef PCL
#include <pcl/io/ply_io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#endif
#define EXPORT __attribute__ ((visibility("default")))

typedef enum {
    STATUS_SUCCESS,
    STATUS_ERROR,
    STATUS_SOCKET_FAILED,           
    STATUS_SOCKET_CONNECT_FAILED,   
    STATUS_SOCKET_SEND_FAILED,
    STATUS_INTRINSICS_ERROR,      
    STATUS_HANDLE_FAILED,
}ERROR_CODE;



/**
 * @brief 
 *      Image type.
 */
typedef enum {
    IMG_DEPTH,
    IMG_AMPLITUDE,
    IMG_RGB,
}IMG_TYPE;

/**
 * @brief 
 *      Image data.
 */
typedef struct {
    IMG_TYPE type;
    int len;
    uint16_t *data;
}STRC_IMG;

typedef struct 
{
    STRC_IMG img_rgb;
    STRC_IMG img_amplitude;
    STRC_IMG img_depth;
#ifdef PCL
    pcl::PointCloud<pcl::PointXYZ>::Ptr pCloud;
#endif
} STRC_IMG_ALL;

#ifdef __cplusplus
extern "C"{
#endif

/**
 * @brief 
 *      SDK initialization
 */
void api_init();

/**
 * @brief 
 *      exit SDK
 */
void api_exit();


/**
 * @brief 
 *      Connect to device.
 * @param ip 
 *      IP of the device.
 * @param port
 *      Port of the device. 
 * @return int 
 *      <0  failed
 *      >=0 success,The handle of the device.
 */
int api_connect(char *ip , int port=65300);

/**
 * @brief 
 *      Disconnect from the device.      
 * @param handle 
 *      The handle of the device.
 * @return int 
 *      >=0     success
 *      <0      failed
 */
int api_disconnect(int handle);


/**
 * @brief 
 *      Get the version of the SDK
 * @return char* 
 *      The version of the SDK
 */
char *api_get_sdk_ver();

/**
 * @brief 
 *      Get the version of the device.
 * @param handle 
 *      The handle of the device.
 * @return char* 
 *      ==NULL  failed
 *      !=NULL  the version of the device
 */
char *api_get_dev_ver(int handle);
/**
 * @brief 
 *      Get the camera intrinsic parameters.
 * @param handle 
 *      The handle of the device.
 * @return char* 
 *      ==NULL  failed
 *      !=NULL  The camera intrinsic parameters.
 */
char *api_get_intrinsic_parameters(int handle);
/**
 * @brief 
 *      Get image.
 * @param handle 
 *      The handle of the device.
 * @return STRC_IMG_ALL* 
 *      ==NULL     No data.
 *      !=NULL     Data of the image.
 * 
 */
STRC_IMG_ALL *api_get_img(int handle );

/**
 * @brief 
 *      Get the last error code.
 * @return ERROR_CODE 
 */
ERROR_CODE api_errorcode();

/**
 * @brief 
 *      Gets the current camera exposure level
 * @param handle 
 *      The handle of the device.
 * @param min
 *      Minimum exposure level returned
 * @param max
 *      Maximum exposure level returned
 * @return int 
 *      >=0 The current exposure level
 *      <0  failed
 *      ==-1    Initialization incomplete
 *      
 */


int api_get_exposure(int handle , int *min , int *max);
/**
 * @brief 
 *      Set exposure level.
 * @param handle 
 *      The handle of the device.
 * @param exposure 
 *      exposure level
 * @return int 
 *      >=0 success
 *      <0  failed
 */
int api_set_exposure(int handle , int exposure);

/**
 * @brief
 *      Set gamma of amplitude image.
 * @param handle
 *      The handle of the device.
 * @param gama
 *      gamma value
 * @param isActive
 *      Whether to enable gamma correction
 * @return int
 *      >=0 success
 *      <0  failed
 */
int api_set_gamma_amplitude(int handle , float gama , bool isActive);

/**
 * @brief
 *      Gets the serial number of the tof module.
 * @param handle
 *      The handle of the device.
 * @return char*
 *      ==NULL     No data.
 *      !=NULL     Data of the SN.
 */
char *api_get_sn_tof(int handle);

/**
 * @brief
 *      Determine the number of frames for superposition.
 * @param handle
 *      The handle of the device.
 * @param num_frames
 *      The number of frames to be superimposed.  The maximum is 10 frames..
 * @return int
 *      >=0 send success
 *      <0  send failed
 */
int api_set_xin1(int handle , int num_frames);

/**
 * @brief
 *      Set the API working mode to be either blocking or non-blocking.
 * @param handle
 *      The handle of the device.
 * @param blockingActive
 *      true: blocking mode
 *      false: non-blocking mode
 * @return int
 *      >=0  success
 *      <0   failed
 */
int api_set_blocking_mode(int handle, bool blockingActive);

/**
 * @brief
 *      Depth map to PCD format point cloud
 * @param headle
 *      The handle of the device.
 * @param depth
 *      Depth map data
 * @param pcd_data
 *      return point, PCD format point cloud data
 * @return int
 *      >0  The length of the data pointed to by the pcd_data.
 *      <=0  failed
 */
int api_depth2pcd(int handle, uint16_t *depth, char **pcd_data);

/**
 * @brief
 *      Get whether the RGB camera is valid.
 * @param handle
 *      The handle of the device.
 * @param rgb_valid
 *      return value of RGB camera validity.
 * @return int
 *      >=0  success    
 *      <0   failed
 * 
 */
int api_get_rgb_valid(int handle , bool *rgb_valid);
#ifdef __cplusplus
}
#endif
